package base.Chapter00_Structures.C01_Array;

import org.testng.annotations.Test;

/**
 * 方法2: 二分法
 * 逻辑:
 * 从最少的开始拆, 如果最少的里面有, 那么
 * 1 1 1 1 1 10 05 10 10     15
 *
 * 转化: 目标转化为可以使用二分法分治
 *
 * 连续n项和 >=k, 找最小的n
 *
 */
public class L862_和至少为K的最短子数组2 {
    public int shortestSubarray(int[] nums, int k) {
        if (nums == null || nums.length < 1) {
            return -1;
        }
        if (nums.length == 1)
            if (nums[0] >= k)
                return 1;
        findN(nums, k, 0, nums.length);

        return -1;
    }

    public int findN(int[] nums, int k, int from, int to) {
        if (from > to) {
            return -1;
        }

        int mid = from + ((to - from) >> 1);

        int n1 = findN(nums, k, from, mid);
        int n2 = findN(nums, k, mid + 1, to);

        return -1;
    }

    @Test
    public void testMethod() {
        int[] nums1 = {77, 19, 35, 10, -14};
        int[] nums = {17, 85, 93, -45, -21};
        System.out.println(shortestSubarray(nums, 150));
    }
}
